package com.matu.controller;

import java.util.ArrayList;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.matu.domain.Personnel;
import com.matu.util.DB;


@Controller
public class ResetController {

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/reset", method = RequestMethod.GET)
	public String reset(Locale locale, Model model) {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		DB db = new DB();
		db.clearDB();
		
		Personnel steve = new Personnel("Steve","pass");
		db.create(steve);
		
		Personnel paul = new Personnel("Paul","pass");
		db.create(paul);
		
		Personnel pierre = new Personnel("Pierre","pass");
		db.create(pierre);
		
		Personnel jack = new Personnel("Jack","pass");
		db.create(jack);
		
		
		ArrayList<Personnel> listP = db.getClassOfObjectsInDB(Personnel.class);
		String perso = "";
		for (Personnel p : listP){
			perso += p.getNom() + " " + p.getPassword() + "<br>";
		}
		model.addAttribute("listP",perso );
		
		
		
		
		
		return "reset";
	}
}
